package net.yihang.exercise;

import net.yihang.entity.Person;
import net.yihang.mapper.PersonMapper;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * 练习2
 * <p>考察知识点：sql语句</p>
 */
public class Exercise2 {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

        // 读取文本文件的武将数据
        List<Person> people = Exercise1.readPersonList();

        // 获取PersonMapper
        PersonMapper mapper = context.getBean(PersonMapper.class);

        // 使用PersonMapper的save方法将数据存入数据库
        for (Person person : people) {
            mapper.save(person);
        }

        context.close();
    }
}
